package cn.xiyun.xiyuncc.MQ.consumer;

import cn.xiyun.xiyuncc.domain.CourseOrder;
import cn.xiyun.xiyuncc.domain.PayOrder;
import cn.xiyun.xiyuncc.dto.Order2PayDto;
import cn.xiyun.xiyuncc.service.ICourseOrderService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(
        consumerGroup = "Transaction-AlipayNotify-group",
        topic = "Alipay_Notify_topic",
        selectorExpression="Alipay_Notify_tags"

        )
public class PayOrderConsumer implements RocketMQListener<String> {
    @Autowired
    private ICourseOrderService courseOrderService;
    @Override
    public void onMessage(String message) {
        Wrapper<CourseOrder> wrapper = new EntityWrapper<>();
        wrapper.eq("order_no",message);
        CourseOrder courseOrder = courseOrderService.selectOne(wrapper);
        courseOrder.setStatusOrder(CourseOrder.ORDER_PAY_SUCCESS);
        System.out.println(courseOrder);
        boolean b = courseOrderService.updateById(courseOrder);
        // FIXME  添加用户与课程的中间表数据

    }
}
